package bhbt.service.log;


import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import bhbt.model.Member;
import bhbt.model.log.LogEle;
import bhbt.model.log.LogElePay;
import bhbt.service.MemberService;
import bhbt.service.core.BaseService;






@Service
public class LogElePayService extends BaseService {
	
	@Resource
    private LogElePayService logElePayService;
	@Resource
    private MemberService memberService;
	@Resource
    private LogEleService logEleService;
	
	public void savePay(LogElePay logElePay){
		logElePayService.saveOrUpdate(logElePay);
		
		Double num = logElePay.getNum();
		
		/**********************业务操作***************************/
		
		//转账会员
		Integer fromMemberId = logElePay.getFromMemberId();
		Member fromMember =memberService.getByKey(fromMemberId);
		
		//接收会员
		Integer toMemberId = logElePay.getToMemberId();
		Member toMember =memberService.getByKey(toMemberId);
		
		
		Map<String, Object> mapMember = new HashMap<String, Object>();
		mapMember.put("id",fromMemberId);
		mapMember.put("diyUpdate","Ele=Ele-"+num);
        //更新余额 
        memberService.update(mapMember);
        
        fromMember= memberService.getByKey(fromMember.getId());
        Double fromYu = fromMember.getEle();
        
        //日志
        LogEle logEleFrom = new LogEle();
        logEleFrom.setMemberId(fromMember.getId());
        logEleFrom.setTitle("转账，接收会员："+toMember.getLoginName()+"。备注："+logElePay.getContent());
        logEleFrom.setState(88);
       
        logEleFrom.setNum(-num);
        logEleFrom.setYu(fromYu);
       
        logEleService.saveOrUpdate(logEleFrom);
        
        
        mapMember = new HashMap<String, Object>();
        mapMember.put("id",toMemberId);
        mapMember.put("diyUpdate","Ele=Ele+"+num);
        //更新余额 
        memberService.update(mapMember);
        toMember= memberService.getByKey(toMember.getId());
        Double toYu = toMember.getEle();
        
        
        //日志
        LogEle logEleTo = new LogEle();
        logEleTo.setMemberId(toMember.getId());
        logEleTo.setTitle("转账，转账会员："+fromMember.getLoginName()+"。备注："+logElePay.getContent());
        logEleTo.setState(88);
        logEleTo.setNum(num);
        logEleTo.setYu(toYu);
       
        logEleService.saveOrUpdate(logEleTo);
        
         
		
	}

}
